package nl.han.dare2date.service.web.applyregistration.CreditcardCompany;

import nl.han.dare2date.service.web.applyregistration.model.ApplyRegistrationResponse;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;

/**
 * Created with IntelliJ IDEA.
 * User: Tom
 * Date: 24-6-13
 * Time: 10:37
 */
public class CreditCardValidationRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("activemq:queue:CreditCardValidationQueue")
            .process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                    ApplyRegistrationResponse applyRegistrationResponse = exchange.getIn().getBody(ApplyRegistrationResponse.class);
                    ExternalCreditcardValidationService externalCreditcardValidationService = new ExternalCreditcardValidationService();
                    applyRegistrationResponse.getRegistration().setSuccesFul(externalCreditcardValidationService.checkCreditCard(applyRegistrationResponse.getRegistration().getUser().getCard()));
                    exchange.getOut().setBody(applyRegistrationResponse);
                    exchange.getOut().setHeader("bool", applyRegistrationResponse.getRegistration().isSuccesFul());
                    System.out.println(externalCreditcardValidationService.checkCreditCard(applyRegistrationResponse.getRegistration().getUser().getCard()));
                }
            })


            .to("activemq:queue:CreditCardValidationResponseQueue");

    }
}
